using System;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;

  public partial class C : Page
  {
      protected void Page_Init(object sender,EventArgs e)
      {
      }
      protected void Page_Load( object sender,EventArgs e )
      {
      }
  }

  public class HtmlFormItem
  {
      public string Tag = "";
      public string Type = "";
      public string Name = "";
      public string Value = "";
      
      public static HtmlFormItem Parse( string s )
      {
          string[] ss = Regex.Replace( s,"\\s+"," " ).Split( ' ' );
          HtmlFormItem item = new HtmlFormItem();
          item.Tag = ss[0];
          item.Type = ss[1];
          item.Name = ss[2];
          if( 3<ss.Length ){
              item.Value = ss[3];
          }
          
          return item;
      }
      public static HtmlFormItem[] Parse( string[] ss )
      {
          HtmlFormItem[] items = new HtmlFormItem[ss.Length];
          for( int i=0,len=items.Length;i<len;i++ ){
              items[i] = Parse( ss[i] );
          }
          return items;
      }
  }
  

/**  
  public class GenHtmlFormClass
  {        
      // Handler  
      public static string Handler( NameValueCollection nvc )
      {
          string code = nvc["code"];
          if( string.IsNullOrEmpty(code) ){
              return "";
          }
          
          StringBuilder sb = new StringBuilder();
          string[] ss = Regex.Replace( code,"\r\n","\n" ).Split( '\n' );
          HtmlFormItem[] items = HtmlFormItem.Parse( ss );
          
          sb.Append( "      #region Public Properties\r\n" );          
          sb.Append( GenHtmlFormClass.Properties( items ) );
          sb.Append( "      #endregion Public Properties\r\n\r\n" );          

          sb.Append( "      #region IEnumerable 接口\r\n" );
          sb.Append( GenHtmlFormClass.IEnumerableMethod( items ) );
          sb.Append( "      #endregion IEnumerable 接口\r\n\r\n" );

          sb.Append( "      #region Public Method\r\n" );
          sb.Append( GenHtmlFormClass.ToStringMethod() );
          sb.Append( "      #endregion Public Method\r\n\r\n" );
          
          sb.Append( "      #region Private Member\r\n" );
          sb.Append( GenHtmlFormClass.Members( items )  );
          sb.Append( "      #endregion Private Member\r\n" );

          sb.Append( "      ==============以下代码不属于HtmlForm类===================\r\n" );
          sb.Append( GenHtmlFormClass.ParseTo( items )  );
          //sb.Append( "      #endregion Private Member\r\n" );

          return sb.ToString();
      }
      
      // 生成私有成员
      public static string Members( HtmlFormItem[] items )
      {
          StringBuilder sb = new StringBuilder();
          for( int i=0,len=items.Length;i<len;i++ ){
              sb.Append( string.Format( "        private {0} _{1} = {2};\r\n",
                                          items[i].Type,
                                          items[i].Sign,
                                          items[i].Default
                                       ));
          }
          return sb.ToString();
      }
      
      // 生成属性
      public static string Properties( HtmlFormItem[] items )
      {
          StringBuilder sb = new StringBuilder();
          for( int i=0,len=items.Length;i<len;i++ ){
              sb.Append( string.Format(
@"        public virtual {0} {1}
        {{
            get{{ return _{1};  }}
            set{{ _{1} = value; }}
        }}
",
        items[i].Type,
        items[i].Sign
                                       ));
          }
          return sb.ToString();
      }
      
      // 生成IEnumerable接口方法
      public static string IEnumerableMethod( HtmlFormItem[] items )
      {
          StringBuilder sb = new StringBuilder();
          sb.Append( 
@"        public IEnumerator GetEnumerator()
        {
" );
          for( int i=0,len=items.Length;i<len;i++ ){
              sb.Append( "            yield return this."+items[i].Sign+";\r\n" );
          }
          sb.Append( "        }\r\n" );
          return sb.ToString();
      }
      
      // 生成ToString方法
      public static string ToStringMethod()
      {
        return 
@"        public override string ToString()
        {
            List<string> list = new List<string>();
            foreach( object o in this ){
                list.Add( o.ToString() );
            }
            return string.Join( ""\r\n"",list.ToArray() );
        }
";
      }
      
      // 生成数据表转换代码,此方法不属于HtmlForm
      public static string ParseTo( HtmlFormItem[] items )
      {
          StringBuilder sb = new StringBuilder();
          sb.Append(
@"        public XxxInfo ParseToXxxInfo( DataRow row )
        {
            if( null==row ){ throw new ArgumentNullException( ""参数不能为null"" );  }
            
            XxxInfo info = new XxxInfo();
            DataColumnCollection dcc = row.Table.Columns;

");
          for( int i=0,len=items.Length;i<len;i++ ){
               sb.Append( string.Format( 
               "            if( dcc.Contains(_{0}) && DBNull.Value!=row[_{0}] ){{ info.{0} = ({1})row[_{0}];  }}\r\n",
                            items[i].Sign,
                            items[i].Type
                            ));
          }
          sb.Append(
@"
            return info;
        }
");
          
          sb.Append( "\r\n" );
          
          sb.Append( "      #region Private Member\r\n" );
          for( int i=0,len=items.Length;i<len;i++ ){
              sb.Append( string.Format(
              "        private string _{0} = \"\";\r\n",
                       items[i].Sign
              ));
          }
          sb.Append( "      #endregion Private Member\r\n" );
          return sb.ToString();
      }
  }
*/